using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using QuartzTypeLib;
namespace etbTOEIC
{
	/// <summary>
	/// Summary description for frmQuestion.
	/// </summary>
	public class FormQuestion : System.Windows.Forms.Form
	{

		public long SectionID = 0;
		public long TopicID = 0;
		public long QuestionID = 0;

		
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.TabControl tabControl2;
		private System.Windows.Forms.TabPage tabPage3;
		private System.Windows.Forms.GroupBox groupBoxClassify;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.GroupBox groupBoxAns;
		private System.Windows.Forms.GroupBox groupBoxQues;
		private System.Windows.Forms.Label labelChoiceD;
		private System.Windows.Forms.Label labelChoiceC;
		private System.Windows.Forms.Label labelChoiceB;
		private System.Windows.Forms.Label labelChoiceA;
		private System.Windows.Forms.GroupBox groupBoxNote;
		private System.Windows.Forms.GroupBox groupBoxImage;
		private System.Windows.Forms.TextBox txtImage;
		private System.Windows.Forms.Button btnImage;
		private System.Windows.Forms.PictureBox pBoxImage;
		private System.Windows.Forms.GroupBox groupBoxSound;
		private System.Windows.Forms.TextBox txtSound;
		private System.Windows.Forms.Button btnSound;
		private System.Windows.Forms.Button btnPlay;
		private System.Windows.Forms.TextBox txtTape;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtDiffLevel;
		private System.Windows.Forms.ComboBox cmbBook;
		private System.Windows.Forms.TextBox txtAnswer;
		private System.Windows.Forms.TextBox txtChoiceD;
		private System.Windows.Forms.TextBox txtChoiceC;
		private System.Windows.Forms.TextBox txtChoiceB;
		private System.Windows.Forms.TextBox txtChoiceA;
		private System.Windows.Forms.TextBox txtQuestion;
		private System.Windows.Forms.TextBox txtTopicTitle;
		private System.Windows.Forms.TextBox txtSectionTitle;
		private System.Windows.Forms.TextBox txtNotes;
		private System.Windows.Forms.Button buttonCancel;
		private System.Windows.Forms.Button buttonOK;
		private System.Windows.Forms.Button btnUnderLine;
		private System.Windows.Forms.Button btnNormal;
		// media 
		private const int WM_APP = 0x8000;
		private const int WM_GRAPHNOTIFY = WM_APP + 1;
		private const int EC_COMPLETE = 0x01;
		private const int WS_CHILD = 0x40000000;
		private const int WS_CLIPCHILDREN = 0x2000000;

		private FilgraphManager m_objFilterGraph = null;
		private IBasicAudio m_objBasicAudio = null;
		private IVideoWindow m_objVideoWindow = null;
		private IMediaEvent m_objMediaEvent = null;
		private IMediaEventEx m_objMediaEventEx = null;
		private IMediaPosition m_objMediaPosition = null;
		private IMediaControl m_objMediaControl = null;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormQuestion(long SID, long TID, long QID,string stSection,string stTopic)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			SectionID = SID;
			TopicID = TID;
			QuestionID = QID;
			txtSectionTitle.Text  = stSection;
			txtTopicTitle.Text = stTopic;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormQuestion));
			this.buttonCancel = new System.Windows.Forms.Button();
			this.buttonOK = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.tabControl2 = new System.Windows.Forms.TabControl();
			this.tabPage3 = new System.Windows.Forms.TabPage();
			this.groupBoxClassify = new System.Windows.Forms.GroupBox();
			this.txtDiffLevel = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.cmbBook = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.groupBoxAns = new System.Windows.Forms.GroupBox();
			this.txtAnswer = new System.Windows.Forms.TextBox();
			this.groupBoxQues = new System.Windows.Forms.GroupBox();
			this.txtChoiceD = new System.Windows.Forms.TextBox();
			this.labelChoiceD = new System.Windows.Forms.Label();
			this.txtChoiceC = new System.Windows.Forms.TextBox();
			this.labelChoiceC = new System.Windows.Forms.Label();
			this.txtChoiceB = new System.Windows.Forms.TextBox();
			this.labelChoiceB = new System.Windows.Forms.Label();
			this.txtChoiceA = new System.Windows.Forms.TextBox();
			this.labelChoiceA = new System.Windows.Forms.Label();
			this.txtQuestion = new System.Windows.Forms.TextBox();
			this.btnUnderLine = new System.Windows.Forms.Button();
			this.btnNormal = new System.Windows.Forms.Button();
			this.groupBoxNote = new System.Windows.Forms.GroupBox();
			this.txtNotes = new System.Windows.Forms.TextBox();
			this.groupBoxImage = new System.Windows.Forms.GroupBox();
			this.txtImage = new System.Windows.Forms.TextBox();
			this.btnImage = new System.Windows.Forms.Button();
			this.pBoxImage = new System.Windows.Forms.PictureBox();
			this.groupBoxSound = new System.Windows.Forms.GroupBox();
			this.txtSound = new System.Windows.Forms.TextBox();
			this.btnSound = new System.Windows.Forms.Button();
			this.btnPlay = new System.Windows.Forms.Button();
			this.txtTape = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.txtTopicTitle = new System.Windows.Forms.TextBox();
			this.txtSectionTitle = new System.Windows.Forms.TextBox();
			this.tabControl2.SuspendLayout();
			this.tabPage3.SuspendLayout();
			this.groupBoxClassify.SuspendLayout();
			this.groupBoxAns.SuspendLayout();
			this.groupBoxQues.SuspendLayout();
			this.groupBoxNote.SuspendLayout();
			this.groupBoxImage.SuspendLayout();
			this.groupBoxSound.SuspendLayout();
			this.SuspendLayout();
			// 
			// buttonCancel
			// 
			this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.buttonCancel.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.buttonCancel.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonCancel.BackgroundImage")));
			this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.buttonCancel.Location = new System.Drawing.Point(508, 647);
			this.buttonCancel.Name = "buttonCancel";
			this.buttonCancel.Size = new System.Drawing.Size(96, 32);
			this.buttonCancel.TabIndex = 23;
			this.buttonCancel.Text = "&Cancel";
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// buttonOK
			// 
			this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.buttonOK.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.buttonOK.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonOK.BackgroundImage")));
			this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.buttonOK.Location = new System.Drawing.Point(392, 647);
			this.buttonOK.Name = "buttonOK";
			this.buttonOK.Size = new System.Drawing.Size(96, 32);
			this.buttonOK.TabIndex = 22;
			this.buttonOK.Text = "&Save";
			this.buttonOK.Click += new System.EventHandler(this.buttonOk_Click);
			// 
			// button1
			// 
			this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button1.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
			this.button1.Enabled = false;
			this.button1.Location = new System.Drawing.Point(620, 647);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(96, 32);
			this.button1.TabIndex = 24;
			this.button1.Text = "&Help";
			// 
			// tabControl2
			// 
			this.tabControl2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.tabControl2.Controls.Add(this.tabPage3);
			this.tabControl2.Location = new System.Drawing.Point(-4, 0);
			this.tabControl2.Name = "tabControl2";
			this.tabControl2.SelectedIndex = 0;
			this.tabControl2.Size = new System.Drawing.Size(736, 632);
			this.tabControl2.TabIndex = 21;
			// 
			// tabPage3
			// 
			this.tabPage3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("tabPage3.BackgroundImage")));
			this.tabPage3.Controls.Add(this.groupBoxClassify);
			this.tabPage3.Controls.Add(this.groupBoxAns);
			this.tabPage3.Controls.Add(this.groupBoxQues);
			this.tabPage3.Controls.Add(this.groupBoxNote);
			this.tabPage3.Controls.Add(this.groupBoxImage);
			this.tabPage3.Controls.Add(this.groupBoxSound);
			this.tabPage3.Controls.Add(this.label2);
			this.tabPage3.Controls.Add(this.label1);
			this.tabPage3.Controls.Add(this.txtTopicTitle);
			this.tabPage3.Controls.Add(this.txtSectionTitle);
			this.tabPage3.Location = new System.Drawing.Point(4, 25);
			this.tabPage3.Name = "tabPage3";
			this.tabPage3.Size = new System.Drawing.Size(728, 603);
			this.tabPage3.TabIndex = 0;
			this.tabPage3.Text = "Question Infomation";
			// 
			// groupBoxClassify
			// 
			this.groupBoxClassify.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.groupBoxClassify.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxClassify.BackgroundImage")));
			this.groupBoxClassify.Controls.Add(this.txtDiffLevel);
			this.groupBoxClassify.Controls.Add(this.label7);
			this.groupBoxClassify.Controls.Add(this.cmbBook);
			this.groupBoxClassify.Controls.Add(this.label4);
			this.groupBoxClassify.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxClassify.Location = new System.Drawing.Point(112, 501);
			this.groupBoxClassify.Name = "groupBoxClassify";
			this.groupBoxClassify.Size = new System.Drawing.Size(248, 96);
			this.groupBoxClassify.TabIndex = 55;
			this.groupBoxClassify.TabStop = false;
			this.groupBoxClassify.Text = "Classify Infomation";
			// 
			// txtDiffLevel
			// 
			this.txtDiffLevel.Location = new System.Drawing.Point(112, 24);
			this.txtDiffLevel.Name = "txtDiffLevel";
			this.txtDiffLevel.Size = new System.Drawing.Size(128, 23);
			this.txtDiffLevel.TabIndex = 50;
			this.txtDiffLevel.Text = "0";
			// 
			// label7
			// 
			this.label7.BackColor = System.Drawing.Color.Transparent;
			this.label7.Location = new System.Drawing.Point(8, 24);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(88, 24);
			this.label7.TabIndex = 49;
			this.label7.Text = "Difficult &Level";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// cmbBook
			// 
			this.cmbBook.Location = new System.Drawing.Point(88, 56);
			this.cmbBook.Name = "cmbBook";
			this.cmbBook.Size = new System.Drawing.Size(152, 24);
			this.cmbBook.TabIndex = 48;
			this.cmbBook.Text = "comboBox1";
			// 
			// label4
			// 
			this.label4.BackColor = System.Drawing.Color.Transparent;
			this.label4.Location = new System.Drawing.Point(8, 56);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(80, 16);
			this.label4.TabIndex = 47;
			this.label4.Text = "&Book Name:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// groupBoxAns
			// 
			this.groupBoxAns.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.groupBoxAns.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxAns.BackgroundImage")));
			this.groupBoxAns.Controls.Add(this.txtAnswer);
			this.groupBoxAns.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxAns.Location = new System.Drawing.Point(8, 501);
			this.groupBoxAns.Name = "groupBoxAns";
			this.groupBoxAns.Size = new System.Drawing.Size(96, 96);
			this.groupBoxAns.TabIndex = 54;
			this.groupBoxAns.TabStop = false;
			this.groupBoxAns.Text = "Answer";
			// 
			// txtAnswer
			// 
			this.txtAnswer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtAnswer.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtAnswer.Location = new System.Drawing.Point(8, 25);
			this.txtAnswer.Multiline = true;
			this.txtAnswer.Name = "txtAnswer";
			this.txtAnswer.Size = new System.Drawing.Size(80, 63);
			this.txtAnswer.TabIndex = 26;
			this.txtAnswer.Text = "";
			this.txtAnswer.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// groupBoxQues
			// 
			this.groupBoxQues.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBoxQues.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxQues.BackgroundImage")));
			this.groupBoxQues.Controls.Add(this.labelChoiceD);
			this.groupBoxQues.Controls.Add(this.txtChoiceC);
			this.groupBoxQues.Controls.Add(this.labelChoiceC);
			this.groupBoxQues.Controls.Add(this.labelChoiceB);
			this.groupBoxQues.Controls.Add(this.txtChoiceA);
			this.groupBoxQues.Controls.Add(this.labelChoiceA);
			this.groupBoxQues.Controls.Add(this.txtQuestion);
			this.groupBoxQues.Controls.Add(this.txtChoiceD);
			this.groupBoxQues.Controls.Add(this.txtChoiceB);
			this.groupBoxQues.Controls.Add(this.btnUnderLine);
			this.groupBoxQues.Controls.Add(this.btnNormal);
			this.groupBoxQues.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxQues.Location = new System.Drawing.Point(8, 296);
			this.groupBoxQues.Name = "groupBoxQues";
			this.groupBoxQues.Size = new System.Drawing.Size(712, 197);
			this.groupBoxQues.TabIndex = 51;
			this.groupBoxQues.TabStop = false;
			this.groupBoxQues.Text = "&Question && Choices";
			// 
			// txtChoiceD
			// 
			this.txtChoiceD.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtChoiceD.Location = new System.Drawing.Point(392, 152);
			this.txtChoiceD.Multiline = true;
			this.txtChoiceD.Name = "txtChoiceD";
			this.txtChoiceD.Size = new System.Drawing.Size(312, 40);
			this.txtChoiceD.TabIndex = 58;
			this.txtChoiceD.Text = "";
			// 
			// labelChoiceD
			// 
			this.labelChoiceD.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.labelChoiceD.BackColor = System.Drawing.Color.Transparent;
			this.labelChoiceD.Location = new System.Drawing.Point(368, 141);
			this.labelChoiceD.Name = "labelChoiceD";
			this.labelChoiceD.Size = new System.Drawing.Size(24, 24);
			this.labelChoiceD.TabIndex = 57;
			this.labelChoiceD.Text = "(D)";
			this.labelChoiceD.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtChoiceC
			// 
			this.txtChoiceC.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtChoiceC.Location = new System.Drawing.Point(392, 101);
			this.txtChoiceC.Multiline = true;
			this.txtChoiceC.Name = "txtChoiceC";
			this.txtChoiceC.Size = new System.Drawing.Size(312, 40);
			this.txtChoiceC.TabIndex = 56;
			this.txtChoiceC.Text = "";
			// 
			// labelChoiceC
			// 
			this.labelChoiceC.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.labelChoiceC.BackColor = System.Drawing.Color.Transparent;
			this.labelChoiceC.Location = new System.Drawing.Point(368, 101);
			this.labelChoiceC.Name = "labelChoiceC";
			this.labelChoiceC.Size = new System.Drawing.Size(24, 24);
			this.labelChoiceC.TabIndex = 55;
			this.labelChoiceC.Text = "(C)";
			this.labelChoiceC.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtChoiceB
			// 
			this.txtChoiceB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.txtChoiceB.Location = new System.Drawing.Point(32, 152);
			this.txtChoiceB.Multiline = true;
			this.txtChoiceB.Name = "txtChoiceB";
			this.txtChoiceB.Size = new System.Drawing.Size(312, 40);
			this.txtChoiceB.TabIndex = 54;
			this.txtChoiceB.Text = "";
			// 
			// labelChoiceB
			// 
			this.labelChoiceB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.labelChoiceB.BackColor = System.Drawing.Color.Transparent;
			this.labelChoiceB.Location = new System.Drawing.Point(8, 141);
			this.labelChoiceB.Name = "labelChoiceB";
			this.labelChoiceB.Size = new System.Drawing.Size(24, 24);
			this.labelChoiceB.TabIndex = 53;
			this.labelChoiceB.Text = "(B)";
			this.labelChoiceB.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtChoiceA
			// 
			this.txtChoiceA.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.txtChoiceA.Location = new System.Drawing.Point(32, 101);
			this.txtChoiceA.Multiline = true;
			this.txtChoiceA.Name = "txtChoiceA";
			this.txtChoiceA.Size = new System.Drawing.Size(312, 40);
			this.txtChoiceA.TabIndex = 52;
			this.txtChoiceA.Text = "";
			// 
			// labelChoiceA
			// 
			this.labelChoiceA.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.labelChoiceA.BackColor = System.Drawing.Color.Transparent;
			this.labelChoiceA.Location = new System.Drawing.Point(8, 101);
			this.labelChoiceA.Name = "labelChoiceA";
			this.labelChoiceA.Size = new System.Drawing.Size(24, 24);
			this.labelChoiceA.TabIndex = 51;
			this.labelChoiceA.Text = "(A)";
			this.labelChoiceA.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtQuestion
			// 
			this.txtQuestion.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtQuestion.Font = new System.Drawing.Font("Times New Roman", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtQuestion.Location = new System.Drawing.Point(8, 25);
			this.txtQuestion.Multiline = true;
			this.txtQuestion.Name = "txtQuestion";
			this.txtQuestion.Size = new System.Drawing.Size(696, 76);
			this.txtQuestion.TabIndex = 26;
			this.txtQuestion.Text = "";
			// 
			// btnUnderLine
			// 
			this.btnUnderLine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnUnderLine.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.btnUnderLine.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnUnderLine.BackgroundImage")));
			this.btnUnderLine.Location = new System.Drawing.Point(440, 168);
			this.btnUnderLine.Name = "btnUnderLine";
			this.btnUnderLine.Size = new System.Drawing.Size(96, 32);
			this.btnUnderLine.TabIndex = 22;
			this.btnUnderLine.Text = "&UnderLine";
			this.btnUnderLine.Visible = false;
			this.btnUnderLine.Click += new System.EventHandler(this.btnUnderLine_Click);
			// 
			// btnNormal
			// 
			this.btnNormal.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnNormal.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.btnNormal.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnNormal.BackgroundImage")));
			this.btnNormal.Location = new System.Drawing.Point(224, 168);
			this.btnNormal.Name = "btnNormal";
			this.btnNormal.Size = new System.Drawing.Size(96, 32);
			this.btnNormal.TabIndex = 22;
			this.btnNormal.Text = "&Reset";
			this.btnNormal.Click += new System.EventHandler(this.btnNormal_Click);
			// 
			// groupBoxNote
			// 
			this.groupBoxNote.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBoxNote.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxNote.BackgroundImage")));
			this.groupBoxNote.Controls.Add(this.txtNotes);
			this.groupBoxNote.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxNote.Location = new System.Drawing.Point(368, 501);
			this.groupBoxNote.Name = "groupBoxNote";
			this.groupBoxNote.Size = new System.Drawing.Size(352, 96);
			this.groupBoxNote.TabIndex = 50;
			this.groupBoxNote.TabStop = false;
			this.groupBoxNote.Text = "Notes";
			// 
			// txtNotes
			// 
			this.txtNotes.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtNotes.Location = new System.Drawing.Point(8, 25);
			this.txtNotes.Multiline = true;
			this.txtNotes.Name = "txtNotes";
			this.txtNotes.Size = new System.Drawing.Size(336, 63);
			this.txtNotes.TabIndex = 26;
			this.txtNotes.Text = "";
			// 
			// groupBoxImage
			// 
			this.groupBoxImage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBoxImage.BackColor = System.Drawing.Color.Transparent;
			this.groupBoxImage.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxImage.BackgroundImage")));
			this.groupBoxImage.Controls.Add(this.txtImage);
			this.groupBoxImage.Controls.Add(this.btnImage);
			this.groupBoxImage.Controls.Add(this.pBoxImage);
			this.groupBoxImage.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxImage.Location = new System.Drawing.Point(480, 64);
			this.groupBoxImage.Name = "groupBoxImage";
			this.groupBoxImage.Size = new System.Drawing.Size(240, 221);
			this.groupBoxImage.TabIndex = 49;
			this.groupBoxImage.TabStop = false;
			this.groupBoxImage.Text = "&Image";
			// 
			// txtImage
			// 
			this.txtImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.txtImage.Location = new System.Drawing.Point(8, 189);
			this.txtImage.Name = "txtImage";
			this.txtImage.Size = new System.Drawing.Size(184, 23);
			this.txtImage.TabIndex = 47;
			this.txtImage.Text = "";
			// 
			// btnImage
			// 
			this.btnImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnImage.Location = new System.Drawing.Point(200, 189);
			this.btnImage.Name = "btnImage";
			this.btnImage.Size = new System.Drawing.Size(32, 24);
			this.btnImage.TabIndex = 46;
			this.btnImage.Text = "...";
			this.btnImage.Click += new System.EventHandler(this.btnImage_Click);
			// 
			// pBoxImage
			// 
			this.pBoxImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.pBoxImage.Image = ((System.Drawing.Image)(resources.GetObject("pBoxImage.Image")));
			this.pBoxImage.Location = new System.Drawing.Point(8, 25);
			this.pBoxImage.Name = "pBoxImage";
			this.pBoxImage.Size = new System.Drawing.Size(224, 156);
			this.pBoxImage.TabIndex = 45;
			this.pBoxImage.TabStop = false;
			// 
			// groupBoxSound
			// 
			this.groupBoxSound.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBoxSound.BackColor = System.Drawing.Color.Transparent;
			this.groupBoxSound.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBoxSound.BackgroundImage")));
			this.groupBoxSound.Controls.Add(this.txtSound);
			this.groupBoxSound.Controls.Add(this.btnSound);
			this.groupBoxSound.Controls.Add(this.btnPlay);
			this.groupBoxSound.Controls.Add(this.txtTape);
			this.groupBoxSound.ForeColor = System.Drawing.Color.MediumBlue;
			this.groupBoxSound.Location = new System.Drawing.Point(8, 64);
			this.groupBoxSound.Name = "groupBoxSound";
			this.groupBoxSound.Size = new System.Drawing.Size(464, 221);
			this.groupBoxSound.TabIndex = 48;
			this.groupBoxSound.TabStop = false;
			this.groupBoxSound.Text = "&Sound && Tape Script:";
			// 
			// txtSound
			// 
			this.txtSound.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtSound.Location = new System.Drawing.Point(56, 189);
			this.txtSound.Name = "txtSound";
			this.txtSound.Size = new System.Drawing.Size(360, 23);
			this.txtSound.TabIndex = 46;
			this.txtSound.Text = "";
			// 
			// btnSound
			// 
			this.btnSound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnSound.Location = new System.Drawing.Point(424, 189);
			this.btnSound.Name = "btnSound";
			this.btnSound.Size = new System.Drawing.Size(32, 24);
			this.btnSound.TabIndex = 45;
			this.btnSound.Text = "...";
			this.btnSound.Click += new System.EventHandler(this.btnSound_Click);
			// 
			// btnPlay
			// 
			this.btnPlay.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnPlay.Image = ((System.Drawing.Image)(resources.GetObject("btnPlay.Image")));
			this.btnPlay.Location = new System.Drawing.Point(8, 181);
			this.btnPlay.Name = "btnPlay";
			this.btnPlay.Size = new System.Drawing.Size(40, 32);
			this.btnPlay.TabIndex = 44;
			this.btnPlay.Text = ">>";
			this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);
			// 
			// txtTape
			// 
			this.txtTape.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtTape.Location = new System.Drawing.Point(8, 25);
			this.txtTape.Multiline = true;
			this.txtTape.Name = "txtTape";
			this.txtTape.Size = new System.Drawing.Size(448, 156);
			this.txtTape.TabIndex = 23;
			this.txtTape.Text = "";
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.ForeColor = System.Drawing.Color.MediumBlue;
			this.label2.Location = new System.Drawing.Point(24, 8);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 42;
			this.label2.Text = "Section :";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.ForeColor = System.Drawing.Color.MediumBlue;
			this.label1.Location = new System.Drawing.Point(8, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 41;
			this.label1.Text = "Topic Title :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtTopicTitle
			// 
			this.txtTopicTitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtTopicTitle.ForeColor = System.Drawing.Color.Crimson;
			this.txtTopicTitle.Location = new System.Drawing.Point(88, 32);
			this.txtTopicTitle.Name = "txtTopicTitle";
			this.txtTopicTitle.ReadOnly = true;
			this.txtTopicTitle.Size = new System.Drawing.Size(632, 23);
			this.txtTopicTitle.TabIndex = 40;
			this.txtTopicTitle.Text = "";
			// 
			// txtSectionTitle
			// 
			this.txtSectionTitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtSectionTitle.ForeColor = System.Drawing.Color.Blue;
			this.txtSectionTitle.Location = new System.Drawing.Point(88, 8);
			this.txtSectionTitle.Name = "txtSectionTitle";
			this.txtSectionTitle.ReadOnly = true;
			this.txtSectionTitle.Size = new System.Drawing.Size(632, 23);
			this.txtSectionTitle.TabIndex = 24;
			this.txtSectionTitle.Text = "";
			// 
			// FormQuestion
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 16);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(728, 686);
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.buttonOK);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.tabControl2);
			this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "FormQuestion";
			this.ShowInTaskbar = false;
			this.Text = "Question Infomation";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.FormQuestion_Closing);
			this.Load += new System.EventHandler(this.FormQuestion_Load);
			this.tabControl2.ResumeLayout(false);
			this.tabPage3.ResumeLayout(false);
			this.groupBoxClassify.ResumeLayout(false);
			this.groupBoxAns.ResumeLayout(false);
			this.groupBoxQues.ResumeLayout(false);
			this.groupBoxNote.ResumeLayout(false);
			this.groupBoxImage.ResumeLayout(false);
			this.groupBoxSound.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void FormQuestion_Load(object sender, System.EventArgs e)
		{
			this.Text += " - SecID=" + SectionID.ToString();
			this.Text += "#TopicID=" + TopicID.ToString();
			if (QuestionID > 0)
				this.Text += "#QuesID=" + QuestionID.ToString();

			switch (SectionID)
			{
				case 1:
					groupBoxQues.Visible = false;
					Size z4 = new Size(groupBoxSound.Size.Width, groupBoxSound.Size.Height);
					Size z5 = new Size(groupBoxImage.Size.Width, groupBoxImage.Size.Height);
					this.Size = new Size(this.Size.Width, 515);
					groupBoxSound.Size = z4;
					groupBoxImage.Size = z5;
					break;
				case 2:
					groupBoxImage.Visible = groupBoxQues.Visible = false;
					Size z3 = new Size(groupBoxQues.Size.Width, groupBoxSound.Size.Height);
					this.Size = new Size(this.Size.Width, 515);
					groupBoxSound.Size = z3;
					break;
				case 3:
					groupBoxImage.Visible = false;
					groupBoxSound.Size = new Size(groupBoxQues.Size.Width, groupBoxSound.Size.Height);
					groupBoxQues.Anchor = AnchorStyles.Bottom|AnchorStyles.Left|AnchorStyles.Right;
					break;
				case 6:
				case 4:
				case 5:
				case 7:
					if (SectionID == 6)
					{
						labelChoiceA.Visible = labelChoiceB.Visible = labelChoiceC.Visible = labelChoiceD.Visible = false;
						btnUnderLine.Visible = btnNormal.Visible = true;
						txtChoiceA.Visible = txtChoiceB.Visible = txtChoiceC.Visible = txtChoiceD.Visible = false;
						
						txtQuestion.Size = new Size(txtQuestion.Size.Width, groupBoxQues.Size.Height - 60);

					}
					Size z1 = new Size(groupBoxSound.Size.Width, groupBoxSound.Size.Height);
					Size z2 = new Size(groupBoxQues.Size.Width, groupBoxQues.Size.Height);
					this.Size = new Size(this.Size.Width, 490);
					groupBoxSound.Size = z1;
					groupBoxQues.Size = z2;

					groupBoxQues.Location = new System.Drawing.Point(groupBoxQues.Location.X, groupBoxSound.Location.Y);
					
					groupBoxSound.Visible = groupBoxImage.Visible = false;
					break;
			}

			if(QuestionID > 0) //edit
			{
				DB2MainForm.LoadQuestion(TopicID, QuestionID, ref txtQuestion, ref txtChoiceA, ref txtChoiceB, ref txtChoiceC, ref txtChoiceD,ref  txtTape, ref txtImage, ref txtSound, ref txtNotes, ref txtAnswer, ref txtDiffLevel, ref cmbBook);
				// thay the: &nbsp == " " ; <br> = "\r\n"
				string stTemp = txtQuestion.Text;
				ConvertFormat(txtQuestion, true);
 				if(txtImage.Text.Length > 0)
					pBoxImage.Image = Image.FromFile(Environment.CurrentDirectory + "\\Images\\" + txtImage.Text);
			}
			else
				DB2MainForm.LoadBooks(ref cmbBook);
			
		}

		private void buttonOk_Click(object sender, System.EventArgs e)
		{
			CleanUp();
			int QuesID = (int)QuestionID;
			int TopID = (int)TopicID;
			if(QuesID == 0)
				MyDatabase.GenerateQuesID(ref QuesID);
			string stQuestion = QuesID.ToString();
			if(stQuestion.Length < 5)
				stQuestion = stQuestion.PadLeft(5,'0');
			string stTopic = TopID.ToString();
			if(stTopic.Length < 5)
				stTopic = stTopic.PadLeft(5,'0');
				
			if(txtSound.Text.Length > 0 && txtSound.Text.IndexOf(":") != -1)
			{
				//copy
				string stExtension = txtSound.Text.Substring(txtSound.Text.Length - 4);
				string stFile = SectionID.ToString() + "T" + stTopic + "Q" + stQuestion + stExtension;
				File.Copy(txtSound.Text, Environment.CurrentDirectory + "\\Sounds\\" + stFile, true);
				txtSound.Text = stFile;
				
			}

			if(txtImage.Text.Length > 0 && txtImage.Text.IndexOf(":") != -1)
			{
				//copy
				string stExtension = txtImage.Text.Substring(txtImage.Text.Length - 4);
				string stFile = SectionID.ToString() + "T" + stTopic + "Q" + stQuestion + stExtension;
				File.Copy(txtImage.Text, Environment.CurrentDirectory + "\\Images\\" + stFile, true);
				txtImage.Text = stFile;
			}
			
			ConvertFormat(txtQuestion, false);
			
			if(QuestionID == 0)
			{
				if(!DB2MainForm.AddQuestion(TopicID, QuestionID, txtQuestion, txtChoiceA, txtChoiceB, txtChoiceC, txtChoiceD, txtTape, txtImage, txtSound, txtNotes, txtAnswer, txtDiffLevel, cmbBook))
				{
					MessageBox.Show("Cannot add question","Add Question - Error");
				}
			}
			else
			{
				if(!DB2MainForm.UpdateQuestion(TopicID, QuestionID, txtQuestion, txtChoiceA, txtChoiceB, txtChoiceC, txtChoiceD, txtTape, txtImage, txtSound, txtNotes, txtAnswer, txtDiffLevel, cmbBook))
				{
					MessageBox.Show("Cannot update data.","Update Question - Error");
				}
			}
			this.Close();
		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			CleanUp();
			this.Close();
		}

		private void buttonHelp_Click(object sender, System.EventArgs e)
		{
		
		}

		private void btnSound_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.Filter = "Wave files (*.wav)|*.wav|MP3 files(*.mp3)|*.mp3|All files (*.*)|*.*";
			dlg.RestoreDirectory = true;

			if (dlg.ShowDialog() == DialogResult.OK)
			{
				txtSound.Text = dlg.FileName;
			}
		}

		private void btnImage_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.Filter = "JPEG files (*.jpg)|*.jpg|Gif files(*.gif)|*.gif|Bitmap files(*.bmp)|*.bmp|All files (*.*)|*.*";
			dlg.RestoreDirectory = true;

			if (dlg.ShowDialog() == DialogResult.OK)
			{
				txtImage.Text = dlg.FileName;
				pBoxImage.Image = Image.FromFile(dlg.FileName);
			}
		}

		private void btnPlay_Click(object sender, System.EventArgs e)
		{
			string stFile = txtSound.Text;
			try
			{
			
				if(m_objMediaControl != null)
				{
					CleanUp();
				}
				else
				{
					
					if(stFile.IndexOf(":") == -1)
						stFile = Environment.CurrentDirectory + "\\Sounds\\" + txtSound.Text;
					m_objFilterGraph = new FilgraphManager();
					m_objFilterGraph.RenderFile(stFile);

					m_objBasicAudio = m_objFilterGraph as IBasicAudio;
                
					m_objMediaEvent = m_objFilterGraph as IMediaEvent;

					m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
					m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);

					m_objMediaPosition = m_objFilterGraph as IMediaPosition;

					m_objMediaControl = m_objFilterGraph as IMediaControl;

					m_objMediaControl.Run();
				}
			}catch(Exception)
			{

			}
		}
		private bool isValidData()
		{
			if(txtSound.Text.Trim().Length > 0 && !File.Exists(txtSound.Text.Trim()))
			{
				MessageBox.Show("Topic Information", "Invalid sound file.");
				return false;
			}
			return true;

		}

		private void btnUnderLine_Click(object sender, System.EventArgs e)
		{
			txtQuestion.Text = txtQuestion.Text.Replace(txtQuestion.SelectedText, "<U>" + txtQuestion.SelectedText+ "</U>");
		}

		private void btnNormal_Click(object sender, System.EventArgs e)
		{
			txtQuestion.Text = txtQuestion.Text.Replace("<U>","");
			txtQuestion.Text = txtQuestion.Text.Replace("</U>","");
		
		}
		private void CleanUp()
		{
			if (m_objMediaControl != null)
				m_objMediaControl.Stop();

			

			if (m_objMediaEventEx != null)
				m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

			if (m_objVideoWindow != null)
			{
				m_objVideoWindow.Visible = 0;
				m_objVideoWindow.Owner = 0;
			}

			if (m_objMediaControl != null) m_objMediaControl = null;
			if (m_objMediaPosition != null) m_objMediaPosition = null;
			if (m_objMediaEventEx != null) m_objMediaEventEx = null;
			if (m_objMediaEvent != null) m_objMediaEvent = null;
			if (m_objVideoWindow != null) m_objVideoWindow = null;
			if (m_objBasicAudio != null) m_objBasicAudio = null;
			if (m_objFilterGraph != null) m_objFilterGraph = null;
		}
		protected override void WndProc( ref Message m)
		{
			if (m.Msg == WM_GRAPHNOTIFY)
			{
				int lEventCode;
				int lParam1, lParam2;

				while (true)
				{
					try
					{
						m_objMediaEventEx.GetEvent(out lEventCode, 
							out lParam1,
							out lParam2,
							0); 
 
						m_objMediaEventEx.FreeEventParams(lEventCode, lParam1, lParam2);

						if (lEventCode == EC_COMPLETE)
						{
							CleanUp();
							
						}
					} 
					catch (Exception)
					{
						break;
					}
				}
			}

			base.WndProc(ref m);
		}

		private void FormQuestion_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			CleanUp();
		}
		private void ConvertFormat(TextBox txt, bool isLoading)
		{
			string stTemp = txt.Text;
			if(isLoading)
			{
				stTemp = stTemp.Replace("A", "     A");
				stTemp = stTemp.Replace("A", "A      ");
				stTemp = stTemp.Replace("B", "     B");
				stTemp = stTemp.Replace("B", "B      ");
				stTemp = stTemp.Replace("C", "     C");
				stTemp = stTemp.Replace("C", "C      ");
				stTemp = stTemp.Replace("D", "     D");
				stTemp = stTemp.Replace("&nbsp;", " ");
				stTemp = stTemp.Replace("<br>", "\r\n");
			}else
			{
				stTemp = stTemp.Replace("     A", "A");
				stTemp = stTemp.Replace("A     ", "A");
				stTemp = stTemp.Replace("     B", "B");
				stTemp = stTemp.Replace("B      ", "B");
				stTemp = stTemp.Replace("     C", "C");
				stTemp = stTemp.Replace("C      ", "C");
				stTemp = stTemp.Replace("     D", "D");
				stTemp = stTemp.Replace(" ", "&nbsp;");
				stTemp = stTemp.Replace("\r\n", "<br>");
			}
			
			txt.Text = stTemp;
		}

		
	}
}
